package com.cyj.redischarts.cyj.controller;

import com.cyj.redischarts.cyj.service.ChartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ChartsController {

    @Autowired
    private ChartsService chartsService;

    @GetMapping("/list")
    public String list(){

        return chartsService.list();
    }

    @PostMapping("/add")
    public String add(String name, Double score){

        Long num = chartsService.add(name,score);

        if (num==1){
            return "添加成功";
        }else {
            return "添加失败";
        }

    }

    @GetMapping("/update")
    public String update(String name, Double score){

        Long num = chartsService.add(name,score);

        return "修改成功";

    }

    @GetMapping("/count")
    public String count( Double score1,Double score2){

        Long num = chartsService.count(score1,score2);

        return "该分数段的总人数为。："+num;

    }

    @GetMapping("/sum")
    public String count(){

        Long num = chartsService.sum();

        return "排行榜的总人数为："+num;

    }

}
